package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: sky-take-out_1
 * @package: com.sky.controller.admin
 * @className: CategoryController
 * @author: Eric
 * @description: TODO
 * @date: 2023/10/13 17:09
 * @version: 1.0
 */
@RequestMapping("/admin/category")
@RestController
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 页面
     *
     * @param categoryPageQueryDTO 分类页面查询d去
     * @return {@link Result}<{@link PageResult}>
     */
    @GetMapping("/page")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){
        PageResult pageResult = categoryService.page(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 添加分类
     *
     * @param categoryDTO 类别d到
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping
    public Result<?> addCategory(@RequestBody CategoryDTO categoryDTO){
        categoryService.addCategory(categoryDTO);
        return Result.success();
    }

    /**
     * 按id删除类别
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @DeleteMapping
    public Result<?> deleteCategoryById(Long id){
        categoryService.deleteCategoryById(id);
        return Result.success();
    }

    /**
     * 修改分类
     *
     * @param categoryDTO 类别d到
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping
    public Result<?> modifyClassification(@RequestBody CategoryDTO categoryDTO){
        categoryService.modifyClassification(categoryDTO);
        return Result.success();
    }

    /**
     * 更改状态
     *
     * @param id     id
     * @param status 状态
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/status/{status}")
    public Result<?> changeStatus(Long id, @PathVariable Integer status){
        categoryService.changeStatus(id,status);
        return Result.success();
    }

    /**
     * 按类型查询
     *
     * @param type 类型
     * @return {@link Result}
     */
    @GetMapping("/list")
    public Result queryByType(Integer type){
        List<Category> categoryList = categoryService.queryByType(type);
        return Result.success(categoryList);
    }


}
